package com.huatai.datacenter.service;

import com.huatai.common.util.ObjectUtil;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author gusiyi
 * @version 1.0
 * @className FunctionService
 * @description 描述：质量校验方法
 * @date 2023/6/13 14:32
 */
@Service
public class QualityFunctionService {

	/**
	 * 空值检测
	 * @param sourceData
	 * @return
	 */
	public Map<String,Object> nullDetection(String sourceData) {
		Map<String,Object> resultMap = new HashMap<>(2);
		if (ObjectUtil.isNotEmpty(sourceData)){
			resultMap.put("data",true);
		}else {
			resultMap.put("data",false);
			resultMap.put("msg","源数据值为空");
		}
		return resultMap;
	}

	/**
	 * 小数点至少保留四位校验
	 * @param sourceData
	 * @return
	 */
	public Map<String,Object> decimalFourPlace(String sourceData){
		Map<String,Object> resultMap = new HashMap<>(2);
		if (ObjectUtil.isNotEmpty(sourceData)){
			String matchMath = "^\\-?[0-9]+[.]([0-9]+)?$";
			if (sourceData.matches(matchMath)){
				String[] split = sourceData.split("\\.");
				String decimal = split[1];
				if (decimal.length()>=4){
					resultMap.put("data",true);
				}else {
					resultMap.put("data",false);
					resultMap.put("msg","源数据没有保留四位小数");
				}
			}else {
				resultMap.put("data",false);
				resultMap.put("msg","源数据不是数值");
			}
		}else {
			resultMap.put("data",false);
			resultMap.put("msg","源数据为空");
		}
		return resultMap;
	}
}
